home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20000824-20010305 / 000292_news@columbia.edu _Thu Feb 15 09:45:34 2001.msg < prev    next >
Internet Message Format  |  2020-01-01  |  3KB

  1. Return-Path: <news@columbia.edu>
  2. Received: from watsun.cc.columbia.edu (watsun.cc.columbia.edu [128.59.39.2])
  3.     by monire.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id JAA28660
  4.     for <kermit.misc@cpunix.cc.columbia.edu>; Thu, 15 Feb 2001 09:45:34 -0500 (EST)
  5. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
  6.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id JAA18809
  7.     for <kermit.misc@watsun.cc.columbia.edu>; Thu, 15 Feb 2001 09:45:33 -0500 (EST)
  8. Received: (from news@localhost)
  9.     by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id JAA14519
  10.     for kermit.misc@watsun.cc.columbia.edu; Thu, 15 Feb 2001 09:46:19 -0500 (EST)
  11. X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
  12. From: fdc@columbia.edu (Frank da Cruz)
  13. Subject: Re: interactive/ automated telnet : Better way to do it?
  14. Date: 15 Feb 2001 14:46:18 GMT
  15. Organization: Columbia University
  16. Message-ID: <96gq3q$e5l$1@newsmaster.cc.columbia.edu>
  17. To: kermit.misc@columbia.edu
  18.  
  19. In article <3A8BDF81.FCCEB0A1@iam.unibe.ch>,
  20. Ibrahim Khalil  <ibrahim@iam.unibe.ch> wrote:
  21.  
  22. : Here is an example of executing a command in a remote machine. Is there a
  23. : faster (sleeps make it slower) and reliable (i.e. works all the time) way to
  24. : do it? Also, how can I grab telnet's stdin and stdout ?
  25. : (sleep 1
  26. : echo userid
  27. : sleep 1
  28. : echo password
  29. : sleep 1
  30. : echo ls -la
  31. : sleep 1) |telnet 130.92.66.22
  32. The most straightforward, easy, reliable, fast, and flexible way to do this
  33. sort of thing is with a scriptable telnet client such as C-Kermit:
  34.  
  35.   http://www.columbia.edu/kermit/ckermit.html
  36.  
  37. Here is your script:
  38.  
  39.   #!/usr/local/bin/kermit +
  40.   set host \%1
  41.   if fail exit 1 Can't reach \%1
  42.   input 20 login:
  43.   if fail exit 1 Timeout waiting for login prompt
  44.   lineout \%2
  45.   input 10 Password:
  46.   if fail exit 1 Timeout waiting for password prompt
  47.   lineout \%3
  48.   lineout ls -la
  49.  
  50. The INPUT command waits until the desired prompt appears, times out and
  51. fails after the given number of seconds if it does not, or else returns
  52. immediately and successfully when it does, so no time is wasted.  LINEOUT
  53. sends the given text with the line terminator appropriate to the
  54. connection.  IF SUCCESS and IF FAIL can be used to test whether any
  55. command in the script succeeds or fails.  Of course EXIT is not the only
  56. choice for handling failure; you can put any other command here you want,
  57. including "procedure calls", blocked groups of statements, etc.
  58.  
  59. Put the script into a file (note: the first line must not be indented),
  60. give it execute permission, then just run it.  In this example, we expect
  61. to receive the hostname-or-address as the first parameter, the username
  62. as the second, the password as the third (obviously not a great idea, but
  63. that's what you wanted).  Of course you can also hardwire them into to
  64. the script, prompt for them at runtime, or whatever else you want.  For a
  65. more fully elaborated example, see the autotelnet script in:
  66.  
  67.   http://www.columbia.edu/kermit/ckscripts.html
  68.  
  69. With C-Kermit, you can script anything you could do by hand, as well as
  70. many things you could not do by hand, such as file transfer, arithmetic,
  71. character-set translation, and so on.
  72.  
  73. - Frank